package com.wlhse.controller;

import com.wlhse.entity.AppServicePojo;
import com.wlhse.service.AppService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController("AppServiceController")
@RequestMapping("/api/v1")
//发布版本
public class AppServiceController {

    @Resource
    private AppService appService;

    @RequestMapping(value = "/app_sql", method = RequestMethod.PUT, produces = {"application/json;charset=utf-8"})
    public String updateSql(@RequestBody(required = false) AppServicePojo appServicePojo) throws IOException, InterruptedException {
        return appService.updateSql(appServicePojo.getVersion());
    }

    //传文件
    @RequestMapping(value = "/app_apk", method = RequestMethod.POST, produces = {"application/json;charset=utf-8"})
    public String updateApk(@RequestParam(value = "file", required = false) MultipartFile file){
        return appService.updateApk(file);
    }

    @RequestMapping(value = "/app_apk_time", method = RequestMethod.POST, produces = {"application/json;charset=utf-8"})
    public String updateTime(@RequestBody AppServicePojo appServicePojo){
        return appService.updateTime(appServicePojo);
    }


    @RequestMapping(value = "/app_version/{value}", method = RequestMethod.GET, produces = {"application/json;charset=utf-8"})
    public String getVersion(@PathVariable("value") int value,@ModelAttribute AppServicePojo appServicePojo){
       return appService.getVersion(value,appServicePojo.getIsOrderBy());
    }

    @RequestMapping(value = "/app_enable/{id}", method = RequestMethod.GET, produces = {"application/json;charset=utf-8"})
    public String updateEnable(@PathVariable("id") int id){
        return appService.updateEnable(id);
    }

}
